import type { Room } from "@/types/Room";
import { reactive, ref } from "vue";

const room = ref<Room | null>(null);
const speaking: { userId: number; message: string; timer: number }[] = reactive([]);

export const onRoomInited = () => {
	return new Promise((resolve, reject) => {
		let count = 0;
		fn();
		function fn() {
			count++;
			if (room.value) resolve(null);
			else if (count > 10) reject(null);
			else setTimeout(() => fn(), 500);
		}
	});
};
export const useRoomState = () => ({ room, speaking });
